﻿// Copyright (c) 2014 Morten Bakkedal
// This code is published under the MIT License.

using System;

using FuncLib.Functions;
using FuncLib.Optimization;

namespace FuncLib.DualFunctions
{
	public partial class DualVariable
	{
		public static implicit operator Variable(DualVariable variable)
		{
			return variable.InnerVariable;
		}

		public static VariableAssignment operator |(DualVariable variable, double value)
		{
			// Added to avoid need for explicit conversion in some cases.
			return variable.InnerVariable | value;
		}

		public static VariableConstraint operator <=(DualVariable variable, double value)
		{
			// Added to avoid interpreting a simple variable bound as a non-linear constraint.
			return variable.InnerVariable <= value;
		}

		public static VariableConstraint operator >=(DualVariable variable, double value)
		{
			return variable.InnerVariable >= value;
		}

		public static VariableConstraint operator <=(double value, DualVariable variable)
		{
			return value <= variable.InnerVariable;
		}

		public static VariableConstraint operator >=(double value, DualVariable variable)
		{
			return value >= variable.InnerVariable;
		}

		public static VariableEqualityConstraint operator ==(DualVariable variable, double value)
		{
			return variable.InnerVariable == value;
		}

		public static VariableEqualityConstraint operator !=(DualVariable variable, double value)
		{
			return variable.InnerVariable != value;
		}

		public static VariableEqualityConstraint operator ==(double value, DualVariable variable)
		{
			return value == variable.InnerVariable;
		}

		public static VariableEqualityConstraint operator !=(double value, DualVariable variable)
		{
			return value != variable.InnerVariable;
		}

		public override int GetHashCode()
		{
			// The hash code from Object is fine, but want to get rid of a warning.
			return base.GetHashCode();
		}

		public override bool Equals(object other)
		{
			// The equality from Object is fine, but want to get rid of a warning.
			return base.Equals(other);
		}
	}
}
